package com.ruoyi.system.web.service.impl;

import com.ruoyi.system.domain.HouseResponse;
import com.ruoyi.system.web.mapper.ClientHouseMapper;
import com.ruoyi.system.web.service.ClientHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;

/**
 * @author 姚炜琦
 * @Classname ClientHouseServiceImpl
 * @Description TODO
 * @Date 2022/10/20 11:18
 */
@Service
public class ClientHouseServiceImpl implements ClientHouseService {
    @Autowired
    private ClientHouseMapper clientHouseMapper;

    /**
     * 查询直售房列表
     * @return
     */
    @Override
    public ArrayList<HouseResponse> findClientHouseByTypeOne() {
        ArrayList<HouseResponse> houseList = clientHouseMapper.findClientHouseByTypeOne();
        for (HouseResponse house : houseList) {
            BigDecimal totalPrice = house.getTotalPrice();
            BigDecimal area = house.getArea();
            // 计算直售房屋每平价格
            BigDecimal divide = totalPrice.divide(area,2,BigDecimal.ROUND_HALF_UP);
            // 拼接单位字符串
            String str = "元/㎡";
            String s = divide.toString();
            house.setEveryPrice(s+=str);
        }
        return houseList;
    }

    /**
     * 查询出租房列表
     * @return
     */
    @Override
    public ArrayList<HouseResponse> findClientHouseByTypeTwo() {
        ArrayList<HouseResponse> houseList = clientHouseMapper.findClientHouseByTypeTwo();
        for (HouseResponse house : houseList) {
            // 拼接单位字符串
            String str = "㎡";
            String s = house.getArea().toString();
            house.setZArea(s+= str);
        }
        return houseList;
    }
}
